package com.darkplanet.management.controller;

import com.darkplanet.management.domain.Employee;
import com.darkplanet.management.domain.EmployeeRole;
import com.darkplanet.management.service.EmployeeRoleService;
import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet(urlPatterns= "/RoleLookServlet")
public class RoleLookServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setCharacterEncoding("utf-8");
        HttpSession session = request.getSession();
        Integer employee_id = (Integer) session.getAttribute("employee_id");
        EmployeeRoleService employeeRoleService = new EmployeeRoleService();
        List<EmployeeRole> femployeeRoles = employeeRoleService.getEmployeeRoles(employee_id);
        ObjectMapper objectMapper = new ObjectMapper();
        String employeeRoles = objectMapper.writeValueAsString(femployeeRoles);
        response.getWriter().print(employeeRoles);
    }
}
